home *** CD-ROM | disk | FTP | other *** search
- /*
- Path & Frame demo
-
- This application creates 3 shapes: an oval, diamond, and a path which represents an outline of an "E". We will take these
- 3 shapes and combine them into one called - gOvaloidShape. We can combine these shapes by calling AddToShape (..).
-
- Once we have a single gxShape containing the three shapes, we can operate on the properties of these shapes as a single gxShape.
- By clicking within the content of the window, you can change the following properties: gxColor, pen size, and fill.
-
- NOTES:
- • This file requires the following files to run correctly:
- "graphics shell.c", "ColorLibrary.c", "FontLibrary.c", "GraphicsDebugLibrary.c", "oval library.c",
- "OvalLibrary.c", "ShapeLibrary.c", "TransformLibrary.c".
-
- • For ideal printing of this file, please print in "landscape".
-
- Change History:
-
- 4/96 bob Updated #includes to support changed GX Library names.
- Updated the note regarding the files needed to run.
- Updated the copyright date.
-
- ©1990 -1996 Apple Computer, Inc.
- All rights reserved.
- */
-
- #include <Events.h>
- #include <Windows.h>
-
- #include "FontLibrary.h"
- #include <GXEnvironment.h>
- #include "GraphicsLibraries.h"
- #include "QDLibrary.h"
- #include "graphics shell.h"
-
- #define kFrameWidth ff(7)
-
- //
- // Set up the title and size of the window
- //
- Rect gWindowQDRect = {50, 20, 450, 600};
- Str255 gWindowTitle = "\pPaths & Frames";
-
- //
- // If gDebugging = TRUE, graphics library errors and notices will be posted. This functionality will only work with
- // the "debugging" version of the QuickDraw GX init. If this version of the init is not installed, nothing bad will happen,
- // but these functions will not work.
- //
- Boolean gDebugging = true;
-
-
- //
- // Set "gGiveMeValidation" to TRUE, if you will receive run-time validation.
- //
- Boolean gGiveMeValidation = true;
-
-
- //
- // gGraphicsHeapSize sets the size of the graphics gxHeap created by calling the GXNewGraphicsClient routine
- // in main () within graphics shell.c. You can determine the amount of graphics gxHeap required by using GraphicsBug.
- // With gGraphicsHeapSize set to 55k, I had 5 free blocks left in the graphics gxHeap. Sounds good to me.
- //
- long gGraphicsHeapSize = 55;
-
- gxShape gOvaloidShape;
- gxShape gTextMessageShape;
- Boolean gDrawState = true;
-
-
- /*------ DoInitialization ---------------------------------------------------------------------------------*/
-
- void DoInitialization(aWindow)
- WindowPtr aWindow;
- { gxRectangle ovalGeometricData = {ff(50), ff(150), ff(150), ff(195)};
- gxShape diamond, letterE;
-
- InitCommonColors ();
-
- //
- // Draw a message to the window which tells the user to click within the window for a change.
- //
- gTextMessageShape = GXNewText(35,(unsigned char*)"Click in the window for a change...", nil);
- SetShapeCommonFont(gTextMessageShape, timesFont);
- GXSetShapeTextSize(gTextMessageShape, ff(20));
- GXMoveShapeTo (gTextMessageShape, ff(165), ff(390));
-
- gOvaloidShape = NewOval(&ovalGeometricData);
- GXRotateShape(gOvaloidShape, ff(20), ff(50), ff(150));
-
- diamond = GXNewRectangle(&ovalGeometricData);
- GXRotateShape(diamond, ff(45), ff(20), ff(170));
- AddToShape(gOvaloidShape, diamond);
-
-
- letterE = GXNewText(1,(unsigned char*)"E", nil);
- SetShapeCommonFont(letterE, timesFont);
- GXSetShapeTextSize(letterE, ff(100));
- GXSetShapeType(letterE, gxPathType);
- GXInsetShape(letterE, -ff(5));
- GXSkewShape(letterE, 0, ff(2), 0, 0);
- GXMoveShapeTo(letterE, ff(40), ff(200));
- AddToShape(gOvaloidShape, letterE);
-
- //
- // We can now dispose of our diamond and letterE shapes becasue they are now part of the
- // geometry contained within our "gOvaloidShape" gxShape.
- GXDisposeShape(diamond);
- GXDisposeShape(letterE);
- }
-
-
-
- /*------ DoDraw ---------------------------------------------------------------------------------------*/
-
- void DoDraw(aWindow)
- WindowPtr aWindow;
- {
- GXDrawShape(gTextMessageShape);
-
- GXMoveShapeTo(gOvaloidShape, ff(25), ff(100));
-
- if (gDrawState) {
- GXSetShapeFill(gOvaloidShape, gxEvenOddFill);
- GXDrawShape(gOvaloidShape);
-
- GXMoveShape(gOvaloidShape, ff(130), ff(-80));
- GXSetShapeFill(gOvaloidShape, gxWindingFill);
- GXDrawShape(gOvaloidShape);
-
- GXMoveShape(gOvaloidShape, ff(130), ff(80));
- GXSetShapeFill(gOvaloidShape, gxClosedFrameFill);
- GXDrawShape(gOvaloidShape);
-
- GXMoveShape(gOvaloidShape, ff(130), ff(-80));
- GXSetShapePen(gOvaloidShape, ff(5));
- GXSetShapeFill(gOvaloidShape, gxClosedFrameFill);
- GXDrawShape(gOvaloidShape);
- } else {
-
- //
- // We ignore these notices because we want to change the color, attributes and pen size. If we did not, nothing
- // bad would happen, but you would receive the notice. You can ignore _all_ notices or warnings posted.
- //
- GXIgnoreGraphicsNotice(color_already_set);
- GXIgnoreGraphicsNotice(attributes_already_set);
- GXIgnoreGraphicsNotice(pen_already_set);
-
- GXSetShapeFill(gOvaloidShape, gxClosedFrameFill);
- GXSetShapeStyleAttributes(gOvaloidShape, gxCenterFrameStyle);
- GXSetShapePen(gOvaloidShape, kFrameWidth);
- SetShapeCommonColor(gOvaloidShape, red);
- GXDrawShape(gOvaloidShape);
-
- GXSetShapePen(gOvaloidShape, 0);
- SetShapeCommonColor(gOvaloidShape, gxBlack);
- GXDrawShape(gOvaloidShape);
-
- GXMoveShape(gOvaloidShape, ff(190), ff(-80));
- GXSetShapeStyleAttributes(gOvaloidShape, gxInsideFrameStyle);
- GXSetShapePen(gOvaloidShape, kFrameWidth);
- SetShapeCommonColor(gOvaloidShape, blue);
- GXDrawShape(gOvaloidShape);
-
- GXSetShapePen(gOvaloidShape, 0);
- SetShapeCommonColor(gOvaloidShape, gxBlack);
- GXDrawShape(gOvaloidShape);
-
- GXMoveShape(gOvaloidShape, ff(190), ff(80));
- GXSetShapeStyleAttributes(gOvaloidShape, gxOutsideFrameStyle);
- GXSetShapePen(gOvaloidShape, kFrameWidth);
- SetShapeCommonColor(gOvaloidShape, green);
- GXDrawShape(gOvaloidShape);
-
- GXSetShapePen(gOvaloidShape, 0);
- SetShapeCommonColor(gOvaloidShape, gxBlack);
- GXDrawShape(gOvaloidShape);
-
- //
- // We need to balance all of our GXIgnoreGraphicsNotice calls with GXPopGraphicsNotice calls,
- // thereby preventing the notice stack from overflowing.
- GXPopGraphicsNotice();
- GXPopGraphicsNotice();
- GXPopGraphicsNotice();
- }
- }
-
-
- /*------ DoDispose -------------------------------------------------------------------------------------*/
-
- void DoDispose(aWindow)
- WindowPtr aWindow;
- {
- //
- // You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good
- // form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
- // call to DisposeWindow should dispose of the objects. If you are running the debugging version of the
- // SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
- // can turn notices on in this file by setting gDebugging = TRUE (above).
- //
- GXDisposeShape(gOvaloidShape);
- GXDisposeShape(gTextMessageShape);
- GXDisposeShape(gWindowBoundsShape);
- DisposeCommonColors();
- DisposeWindow(aWindow);
- }
-
-
- /*------ DoClick ---------------------------------------------------------------------------------------*/
-
- void DoClick( orgMouseLoc, theWindow )
- gxPoint orgMouseLoc;
- WindowPtr theWindow;
- {
- SetPort ( theWindow );
- EraseRect( &theWindow->portRect );
-
- gDrawState = !gDrawState;
- DoDraw( theWindow );
- }
-
-
- /*------ DoIdle ----------------------------------------------------------------------------------------*/
- void DoIdle(aWindow)
- WindowPtr aWindow;
- {
- }
-